﻿using RTUDataAcquisition.Utils.Emails.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Tab;

namespace RTUDataAcquisition.Utils.Emails.EmailSendCore
{
    public class QQEmail : BaseEmailInterface
    {
        // 设置发送者的电子邮件地址和密码
        const string senderEmail = "609365252@qq.com";
        //授权码
        const string senderPassword = "iltscuhpsajtbdje";
        //服务器
        const string emailServer = "smtp.qq.com";
        public void SendEmail(SendEmailInputDto sendEmailInputDto)
        {
            string title = sendEmailInputDto.title;
            string body = sendEmailInputDto.body;
            foreach (var receiverEmail in sendEmailInputDto.SendEmails)
            {
                // 创建邮件对象
                MailMessage mail = new MailMessage(senderEmail, receiverEmail);
                mail.Subject = title;
                mail.Body = body;
                // 创建SMTP客户端
                SmtpClient smtpClient = new SmtpClient(emailServer);
                smtpClient.Port = 587;
                smtpClient.Credentials = new NetworkCredential(senderEmail, senderPassword);
                smtpClient.EnableSsl = true;
                smtpClient.Send(mail);
            }
        }
    }
}
